/**
 * @program: LeetCode
 * @description: LeetCode : 剑指 Offer 53 - II. 0～n-1中缺失的数字
 * @author: WXY
 * @create: 2022-12-09 21:11
 * @Version 1.0
 **/


public class Num053_2_missingNumber {
    public static int missingNumber(int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        int mid = 0;
        while (left <= right) {
            mid = left + (right  - left) / 2;
            if (nums[mid] != mid) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return left;

    }

    public static void main(String[] args) {
        int[] arr = {0, 1, 2, 3, 5, 6, 7, 8,9};
        int[] arr1 = {1};
        int i = missingNumber(arr);
        int number = missingNumber(arr1);
        System.out.println(i);
        System.out.println(number);
    }
}
